import { NextRequest, NextResponse } from 'next/server';
import config from '@/config';

// 动态监控配置
let dynamicConfig = {
  minTransactionValueUSD: 5000, // 设置为5000美元
  whaleThresholdUSD: 1000000,
  highRiskThreshold: 70
};

export async function GET() {
  return NextResponse.json({
    success: true,
    config: {
      ...dynamicConfig,
      staticConfig: config.monitoring,
      chains: {
        ethereum: { minValueUSD: 5000 },
        bsc: { minValueUSD: 5000 },
        bitcoin: { minValueUSD: 5000 }
      }
    },
    message: 'Current monitoring configuration'
  });
}

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const { minTransactionValueUSD, whaleThresholdUSD, highRiskThreshold } = body;

    if (minTransactionValueUSD !== undefined) {
      dynamicConfig.minTransactionValueUSD = parseInt(minTransactionValueUSD);
    }
    if (whaleThresholdUSD !== undefined) {
      dynamicConfig.whaleThresholdUSD = parseInt(whaleThresholdUSD);
    }
    if (highRiskThreshold !== undefined) {
      dynamicConfig.highRiskThreshold = parseInt(highRiskThreshold);
    }

    return NextResponse.json({
      success: true,
      config: dynamicConfig,
      message: 'Monitoring configuration updated successfully'
    });

  } catch (error) {
    return NextResponse.json(
      { 
        success: false, 
        error: error instanceof Error ? error.message : 'Unknown error'
      },
      { status: 500 }
    );
  }
}

// 导出配置供其他模块使用
export function getMonitoringConfig() {
  return dynamicConfig;
} 